<include file="Public:head" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="__APP__/Application/{$Think.MODULE_NAME}/Public/css/cart.css"/>
<!--[if lte IE 6]>
  <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap-ie6.css">
  <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/ie.css">
<![endif]-->
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/font-awesome.min.css"/>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="__APP__/Application/{$Think.MODULE_NAME}/Public/css/payorder.css">
<script src="__PUBLIC__/js/jquery/validate.js"></script>
<!--[if lt IE 9]>
<style>
    .md-modal {
        top: 10%;
        left: 20%;
    }
</style>
<![endif]-->
<script type="text/javascript">
    $(function() {
        $("textarea").placeholder();
        if ($(".active").length == 0) {
            $(".addr-card").eq(0).addClass("active");
        }
        jQuery.validator.addMethod("isMobile", function(value, element) {
            var length = value.length;
            var mobile = /^1[3,5,8]\d{9}$/;
            if (value.length > 0) {
                return (mobile.exec(value)) ? true : false;
            } else {
                return true;
            }
        }, "请正确填写您的手机号码");
        $("#form_addr").validate({
            errorPlacement: function(error, element) {
                var error_td = element.parent('td');
                error_td.find('label.error').hide();
                error_td.append(error);
            },
            submitHandler: function(form) {
                addCartAddr();
                return false;
            },
            rules: {
                truename: {
                    required: true,
                    minlength: 2,
                    maxlength: 8
                },
                addr: {
                    required: true,
                    minlength: 4,
                    maxlength: 35
                },
                phone: {
                    required: true,
                    isMobile: true
                },
                phone2: {
                    isMobile: true
                }
            },
            messages: {
                truename: {
                    required: '姓名不能为空',
                    minlength: '姓名必须在2-8个字符之间',
                    maxlength: '姓名必须在2-8个字符之间'
                },
                addr: {
                    required: '地址不能为空',
                    minlength: '地址必须在4-50个字符之间',
                    maxlength: '地址必须在4-50个字符之间'
                },
                phone: {
                    required: "手机号码不能为空",
                    isMobile: "手机号码格式不对"
                },
                phone2: {
                    isMobile: "手机号码格式不对"
                }
            }
        });
    })
    function cartSubmit() {
        var id = $(".address-list").children(".active").attr("data-id");
        if (id > 0) {
            $("#addr_id").val(id);
            document.form_cart.submit();
        } else {
            showTip('系统提示', "请选择收货地址！", '2');
        }
    }
</script>
<script type="text/javascript" src="__PUBLIC__/js/jquery/placeholder.js"></script>
<form action="{:U('Cart/submit')}" method="POST"  name="form_cart" >
    <div class="container-lg" style="height:auto">
        <div class="div-address">
            <h2>选择收货地址</h2>
            <div class="address-list" data-url="{:U('Box/setAddr')}">
                <!-- 此处开始循环地址 -->
                <foreach name="addrs" item="row">
                    <div data-id="{$row.id}" class="addr-card <if condition='$row.is_default eq 1'>active </if>" <if condition='$key%3 eq 2'>style='margin-right:0'</if>>
                        <div class="inner">
                            <div class="addr-hd" title="{$row.truename} 收">
                                <span class="name">{$row.truename} 收</span>
                                <i <if condition="$row['is_default'] eq 1">class="icon-map-marker addr-deafault active"<else/> class="icon-map-marker addr-deafault"</if> title="默认地址"></i>
                            </div>
                            <div title="{$row.country} {$row.addr}" class="addr-bd">
                                <span class="street">{$row.addr}</span>
                                <p class="phone" style="margin:5px 0">{$row.phone}</p>
                                <p class="phone2">{$row.phone2}</p>
                            </div>
                            <div class="addr-toolbar"></div>
                        </div>
                    </div>
                </foreach>

            </div>
            <div class="control">
                <a class="create-addr">使用新地址</a>
                <a class="manage-addr" href="{:U('Member/addr')}">管理收货地址</a>
            </div>
        </div>
        <div class="pay-orders">
            <h2>确认订单信息</h2>
            <!-- 循环店铺 -->
            <div class="all-article">
                <foreach name="cartsArr" item="row">
                    <table class="grid-article">
                        <thead>
                            <tr>
                                <th class="th-title">
                        <div class="title-wrap">
                            <div class="bundle-title">
                                <div class="shop-title">
                                    <span class="label label-danger tt">{$row.name}</span>
                        
                                    {$row.sendtimes|getMinSendTime}
                                </div>
                            </div>
                        </div>
                        </th>
                        <th class="th-price">单价（元）</th>
                        <th class="th-amount">数量</th>
                        <th class="th-promo">优惠（元）</th>
                        <th class="th-bag">其他（元）</th>
                        <th class="th-sum">小计(元)</th>
                        </tr>
                        <tr class="row-border">
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                        </thead>
                        <tbody>

                        <foreach name="row['sub']" item="row2">
                            <tr class="grid-order" data-order="{$row2.id}">

                                <td class="td-master">&nbsp;&nbsp;
                                    {$row2.name}

                                </td>
                                <td class="td-price">{$row2.price}</td>
                                <td class="td-amount">
                                    <div class="tc-amount">{$row2.num}</div>
                                </td>
                                <td class="td-promo">
                                    <div class="order-promo-select">
                                        <div class="tc-select-content">
                                            <p class="tc-select-label">省{$row2.discount}元</p>
                                        </div>
                                    </div>
                                </td>
                                 <td class="td-bag">
                                     <if condition="$row2.is_bag gt 0">打包{$row2['is_bag']*$row2['num']|getOneDot}元<else/>0.0</if>
                                </td>
                                <td class="td-sum">
                                    <p class="sum">{$row2.price_total}</p>
                                    <input type="hidden" name="id[]" value="{$row2.id}">
                                    <input type="hidden" name="num[]" value="{$row2.num}">
                                </td>
                            </tr>
                        </foreach>

                        </tbody>
                        <tr class="tr-remark">
                            <td class="td-remark">
                                <div class="div-remark">
                                    <label class="tips" for="">补充说明：</label>
                                    <div class="input-mask">
                                        <textarea class="mark-text" hideFocus="true" data-maxlength="200" name="remark_{$row.id}" autocomplete="off" placeholder="选填，可告诉卖家您的特殊要求"></textarea>
                                    </div>
                                </div>
                            </td>
                            <td class="td-bill" colspan="5">
                                <div class="sum"style="float:right">
                                   
                                    店铺合计:
                                    <span class="icon-rmb">¥</span> 
                                    <strong class="shop-cost" data-total="{$row.shop_price}">
                                        {$row.shop_price}
                                        <if condition="$row.sales_cut gt 0 && $row['shop_price'] gt $row['sales_full']"> 
                                            -{$row.sales_cut|getOneDot}
                                             <span class="span_price">(减)</span>
                                        </if>
                                       
                                    </strong>
                                    <if condition='$row.sendprice gt 0'>+
                                        {$row.sendprice}<span class="span_price">(配送费)</span>
                                    </if>
                                    <if condition='$row.bags gt 0'>+
                                        {$row.bags|getOneDot}<span class="span_price">(打包费)</span>
                                    </if>
                                     = <span class="icon-rmb">¥</span> 
                                        <strong>{$row['shop_price']-$row['sales_cut']+$row['sendprice']+$row['bags']|getOneDot}</strong>
                                </div>
 </td>
                        </tr>
                    </table>
                </foreach>
            </div>

        </div>
        <div class="pay-confirm" style="display: block;">
            <div class="main">

                <div class="pay-due">
                    <p class="pay-info">
                        <span class="">实付款：</span>
                        <span class="pay-money">
                            <span class="">¥</span>
                            <strong id="total_price" data-total="{$total_price}">
                                {$total_price}
                            </strong>
                        </span>
                    </p>
                    <if condition='$sendtimes eq 0'>
                    <select name='sendtime' autocomplete='off' style='width:120px;margin:10px 0 0'>
                        <option value='0'>立即送出</option>
                        <foreach name="times" item="row">
                            <option value='{$row.t2}'>{$row.t}</option>
                    </foreach>
                    </select>
                        <else/>
                        </if>
                </div>
            </div>
            <!--送餐时间-->

            <div class="div-action">
                         <a  class="back-to-cart" href="{:U('Cart/lists')}" title="返回购物车修改">返回购物车修改</a>
                <input type="hidden" id="addr_id" name="addr_id" />
                <span>
                    <button id="submit_order" data-user-money='{$user.points}' class="btn btn-danger" type="button" onclick="cartSubmit()">提交订单</button>
                </span>
            </div>
        </div>
    </div>
</form>

<div class="md-modal md-effect-1" id="modal-1">
    <form method="POST" enctype="multipart/form-data"   id="form_addr" data-url="">
        <div class="md-content" >
            <h3>
                使用新地址
                <span class="close-md">×</span>
            </h3>
            <table width="80%" class="table_addr" align="center">
                <tr>
                    <td>姓名：<em>*</em></td>
                    <td><input id="truename" type="text"  name="truename" autocomplete="off"/></td>
                </tr>
                <tr>
                    <td>手机：<em>*</em></td>
                    <td><input id="phone" type="text" class="tc-text" name="phone" autocomplete="off"/></td>
                </tr>
                <tr>
                    <td>备选手机：</td>
                    <td><input id="phone2" type="text" class="tc-text" name="phone2" autocomplete="off"/></td>
                </tr>
                <tr>
                    <td>地址：<em>*</em></td>
                    <td><textarea id="addr"  name="addr" autocomplete="off" style="width:240px"/></textarea></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <p style="margin-top:10px">
                            <button class="btn btn-primary"  id="add_newaddr" data-url="{:U('Box/saveAddr')}" data-loading-text="正在处理" type="submit" >确认</button>&nbsp;&nbsp;
                            <button class="btn btn-default md-close" type="button">取消</button>
                        </p>
                    </td>
                </tr>
            </table>
            <div style="height:20px"></div>
        </div>
    </form>
</div>
<div class="md-overlay"></div>
<script type="text/javascript" src="__APP__/Application/{$Think.MODULE_NAME}/Public/js/payorder.js"></script>
<include file="Public:foot" />